﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
public partial class sysadmin_RoleManager_ManagerRole : PowerCreator.LMS.Web.Base.BasePage
{
    private PowerCreator.LMS.Web.Action.Action opAction = new PowerCreator.LMS.Web.Action.Action();
    protected string _stringdel = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            InitPage();
            //lnkbtn_del.Attributes.Add("")
           //lbtn.Attributes.Add("onClick", "javascript:return confirm('确定删除此记录？');");
            string search = GetSearch();
            BinderPager(search);
            BinderRPT(search, 1);
        }
    }
    
    protected override void InitPage()
    {
        _stringdel = GetLanageValueByKey("ManagerRole_btnadd", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Add.Text = GetLanageValueByKey("ManagerRole_btnadd", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    protected void rptRole_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "leditor")
        {
            string url = "EditorRole.aspx?RoleID=" + e.CommandArgument.ToString();
            Script.RedirectURL(url);
        }
        else if (e.CommandName.ToString() == "ldel")
        {
            if (opAction.DeleteRole(int.Parse(e.CommandArgument.ToString())))
            {
                string search = GetSearch();
                BinderPager(search);
                BinderRPT(search, AspNetPager1.CurrentPageIndex);
            }
            else
            {
                lbl_msg_managerrole.Text = GetLanageValueByKey("lbl_msg_managerrole_del", PowerCreator.LMS.Language.LanagetItemType.MSG);
            }
        }
        else if (e.CommandName.ToString() == "editoaction")
        {
            string url = "SetBaseAction.aspx?RoleID=" + e.CommandArgument.ToString();
            Script.RedirectURL(url);
        }
        else if (e.CommandName.ToString() == "lroleuser")   //授权用户
        {
            string url = "RoleSelectUser.aspx?RoleID=" + e.CommandArgument.ToString();
            Script.RedirectURL(url);
        }
        else if (e.CommandName.ToString() == "luser")   //查看用户
        {
            string url = "RoleUser.aspx?RoleID=" + e.CommandArgument.ToString();
            Script.RedirectURL(url);
        }

    }
    private string GetSearch()
    {
        string search = "";
        return search;
    }
    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = opAction.QueryRoleCount(search);
        AspNetPager1.PageSize = LMSPageSize;
    }
    public void BinderRPT(string search,int pageIndex)
    {
        DataTable dt = opAction.QueryRole(search, "", LMSPageSize, pageIndex);

        dt.Columns.Add("SortRoleDescription");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            
            dt.Rows[i]["SortRoleDescription"] = PowerCreator.LMS.Common.Utils.StringUtils.Left(dt.Rows[i]["RoleDescription"].ToString(), 36);
            
            
        }
        rptRole.DataSource = dt;
        rptRole.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderRPT(search, AspNetPager1.CurrentPageIndex);
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        string url = "ActionManage.aspx";
        Script.RedirectURL(url);
    }
    protected void rptRole_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            LinkButton lnkbtn_del1 = (LinkButton)e.Item.FindControl("lnkbtn_del");            
            lnkbtn_del1.Attributes.Add("onClick", "javascript:return confirm('确定删除此记录？')");
           
        }
        
    }
}
